SVMDIR = '..';
SVMMEXDIR = [SVMDIR filesep 'bin'];
[~,~,~] = mkdir(SVMMEXDIR);
addpath([SVMDIR filesep 'common'], SVMMEXDIR, [SVMDIR filesep 'IBP'], fullfile(SVMDIR, '..', 'daSVM'));

eval(['mex -O -outdir ''' SVMMEXDIR ''' -output zrow_sampler CXXFLAGS="\$CXXFLAGS -std=c++0x" ''' fullfile(SVMDIR, 'common', 'zrow_sampler.cpp') '''']);

regvals = sqrt(sqrt(10)).^[8 7.5 7 6.5 6 5.5 5 4.5 4 3.5 3];
regvals = 1./regvals(end:-1:1);
ell = 9;
alphav = 5;
invsigmaxsqr = 1;
invsigmaetasqr = 1;
invsigmawsqr = 1;

[D,Ntrain] = size(traindata{1}.X);
Ntest = size(testdata{1}.X, 2);
Nall = Ntrain+Ntest;
cachiter = false;

poisstrunc = max(ceil(alphav/Nall+5*sqrt(alphav/Nall)), 10);
invsigmaxsqr = invsigmaxsqr*ones(Nall,1);
algtype = 1;
maxiter = 50;
burnin = 10;

Z_init = ibprnd(Nall, alphav);
K = size(Z_init, 2);
W_init = randn(D,K)./sqrt(invsigmawsqr);
eta_init = randn(K,1)./sqrt(invsigmaetasqr);
invlambda_init = rand(Ntrain, 1);

savedir = input('save to: ', 's');
mkdir(savedir);
save([savedir filesep 'init.mat'], 'Z_init','K','W_init','eta_init','invlambda_init');